package com.taiyuan.ty.controller;

import com.taiyuan.ty.common.R;
import com.taiyuan.ty.request.LikeRequest;
import com.taiyuan.ty.service.PlaceLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : 周桓宇
 * @description :
 * @createDate : 2025/3/26 下午8:33
 */
@RestController
@RequestMapping("/api/placeLike")
public class PlaceLikeController {
    @Autowired
    private PlaceLikeService placeLikeService;

    /**
     * 点赞
     * @param likeRequest
     * @return
     */
    @PostMapping("/like")
    public R<String> likePlace(@RequestBody LikeRequest likeRequest) {
        if (placeLikeService.likePlace(likeRequest.getPlaceId(), likeRequest.getUserId())) {
            return R.success("点赞成功");
        } else {
            return R.error("点赞失败");
        }
    }

    /**
     * 取消点赞
     * @param likeRequest
     * @return
     */
    @PostMapping("/unlike")
    public R<String> unlikePlace(@RequestBody LikeRequest likeRequest) {
        if (placeLikeService.unlikePlace(likeRequest.getPlaceId(), likeRequest.getUserId())) {
            return R.success("取消点赞成功");
        } else {
            return R.error("取消点赞失败");
        }
    }

    /**
     * 获取点赞数量
     * @param placeId
     * @return
     */
    @GetMapping("/count")
    public R<Integer> getPlaceLikesCount(@RequestParam Long placeId) {
        int count = placeLikeService.getPlaceLikesCount(placeId);
        return R.success(count);
    }
}

